package com.guofen.controller.sjq;

import com.guofen.pojo.SjqWaterProductionEquipmentRunning;
import com.guofen.service.sjq.SjqWaterProductionEquipmentRunningService;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/sjq/SjqWaterProductionEquipmentRunning")
@Controller
@Api(tags = "SjqWaterProductionEquipmentRunningController", description = "水处理生产现场记录表（设备运行)")
public class SjqWaterProductionEquipmentRunningController {
    @Autowired
    private SjqWaterProductionEquipmentRunningService sjqWaterProductionEquipmentRunningService;

    @ApiOperation("添加记录（操作人）")
    @RequestMapping(value = "/addForm", method = RequestMethod.POST)
    @ResponseBody
    public Result addForm(@ApiParam(name = "pump_pressure_1", value = "膜泵压力1#", required = true) @RequestParam String pump_pressure_1,
                          @ApiParam(name = "pump_pressure_2", value = "膜泵压力2#", required = true) @RequestParam String pump_pressure_2,
                          @ApiParam(name = "pump_pressure_3", value = "膜泵压力3#", required = true) @RequestParam String pump_pressure_3,
                          @ApiParam(name = "fan_frequency_1", value = "0池风机频率1#", required = true) @RequestParam String fan_frequency_1,
                          @ApiParam(name = "fan_frequency_2", value = "0池风机频率2#", required = true) @RequestParam String fan_frequency_2,
                          @ApiParam(name = "operator", value = "操作人", required = true) @RequestParam String operator){
        double pump_1 = Double.parseDouble(pump_pressure_1);
        double pump_2 = Double.parseDouble(pump_pressure_2);
        double pump_3 = Double.parseDouble(pump_pressure_3);
        double fan_1 = Double.parseDouble(fan_frequency_1);
        double fan_2 = Double.parseDouble(fan_frequency_2);

        if (sjqWaterProductionEquipmentRunningService.addForm(pump_1, pump_2, pump_3, fan_1,  fan_2, operator))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("添加备注及检查人")
    @RequestMapping(value = "/addRemarks", method = RequestMethod.POST)
    @ResponseBody
    public Result addRemarks( @ApiParam(name="id",value="id",required=true) @RequestParam String id,
                              @ApiParam(name = "pump_pressure_1_remark", value = "检查员对设备膜泵压力1#检查的评论", required = false) @RequestParam(required = false) String pump_pressure_1_remark,
                              @ApiParam(name = "pump_pressure_2_remark", value = "检查员对设备膜泵压力2#检查的评论", required = false) @RequestParam(required = false) String pump_pressure_2_remark,
                              @ApiParam(name = "pump_pressure_3_remark", value = "检查员对设备膜泵压力3#检查的评论", required = false) @RequestParam(required = false) String pump_pressure_3_remark,
                              @ApiParam(name = "fan_frequency_1_remark", value = "检查员对设备0池风机频率1#检查的评论", required = false) @RequestParam(required = false) String fan_frequency_1_remark,
                              @ApiParam(name = "fan_frequency_2_remark", value = "检查员对设备0池风机频率2#检查的评论", required = false) @RequestParam(required = false) String fan_frequency_2_remark,
                              @ApiParam(name = "examiner", value = "检查人", required = true) @RequestParam String examiner){
        int Id = Integer.parseInt(id);
        if (sjqWaterProductionEquipmentRunningService.addRemarks(Id,pump_pressure_1_remark,pump_pressure_2_remark,
                pump_pressure_3_remark,fan_frequency_1_remark,fan_frequency_2_remark, examiner)!=null)
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");

    }

    @ApiOperation("获取当天设备运行记录")
    @RequestMapping(value = "/findForm", method = RequestMethod.GET)
    @ResponseBody
    public Result findForm(){
        if (sjqWaterProductionEquipmentRunningService.findForm() != null)
            return ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentRunningService.findForm());
        else
            return ResultGenerator.genFailResult("暂无记录");
    }


    @ApiOperation("删除记录")
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentRunningService.delete(id));
    }

    @ApiOperation("修改记录")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public Result update(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id,
                         @ApiParam(name = "pump_pressure_1", value = "膜泵压力1#", required = true) @RequestParam String pump_pressure_1,
                         @ApiParam(name = "pump_pressure_2", value = "膜泵压力2#", required = true) @RequestParam String pump_pressure_2,
                         @ApiParam(name = "pump_pressure_3", value = "膜泵压力3#", required = true) @RequestParam String pump_pressure_3,
                         @ApiParam(name = "fan_frequency_1", value = "0池风机频率1#", required = true) @RequestParam String fan_frequency_1,
                         @ApiParam(name = "fan_frequency_2", value = "0池风机频率2#", required = true) @RequestParam String fan_frequency_2,
                         @ApiParam(name = "operator", value = "操作人", required = true) @RequestParam String operator,
                         @ApiParam(name = "examiner", value = "检查人", required = true) @RequestParam String examiner) {
        SjqWaterProductionEquipmentRunning record = new SjqWaterProductionEquipmentRunning();
        double p1 = Double.parseDouble(pump_pressure_1);
        double p2 = Double.parseDouble(pump_pressure_2);
        double p3 = Double.parseDouble(pump_pressure_3);
        double f1 = Double.parseDouble(pump_pressure_1);
        double f2 = Double.parseDouble(pump_pressure_2);
        record.setId(id);
        record.setPumpPressure1(p1);
        record.setPumpPressure2(p2);
        record.setPumpPressure3(p3);
        record.setFanFrequency1(f1);
        record.setFanFrequency2(f2);
        record.setOperator(operator);
        record.setExaminer(examiner);
        return ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentRunningService.update(record));
    }

    @ApiOperation("查找记录")
    @RequestMapping(value = "/select",method = RequestMethod.POST)
    @ResponseBody
    public Result select(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间") Long startTime,
                         @ApiParam(name="endTime",value="截止时间") Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentRunningService.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentRunningService.getByTime(pageSize, currentPage, startTime, endTime));
    }
}
